package com.econ.powercloud.ems.service.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.econ.powercloud.ems.dal.entity.ExtIotNode;
import com.econ.powercloud.ems.dal.mapper.ExtIotNodeMapper;
import com.econ.powercloud.ems.pojo.ListingVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author : zjf
 * @Description :
 * @Date : 2022/11/14 15:05
 * @Modified by : zjf
 */
@Repository
public class ExtIotNodeDAO extends ServiceImpl<ExtIotNodeMapper, ExtIotNode> {
    @Autowired
    ExtIotNodeMapper extIotNodeMapper;

    public ExtIotNode selectByNodeId(String nodeId){
        LambdaQueryWrapper<ExtIotNode> lambdaQuery = Wrappers.lambdaQuery();
        lambdaQuery.eq(ExtIotNode::getNodeId,nodeId);
        lambdaQuery.last("limit 1");
        return this.baseMapper.selectOne(lambdaQuery);
    }

    public void updateBatchByNodeId(List<ExtIotNode> childNodeList) {
        extIotNodeMapper.updateBatchByNodeId(childNodeList);
    }

    public List<ExtIotNode> getListingStatusByDeviceCodes(List<String> deviceCodes) {
        LambdaQueryWrapper<ExtIotNode> lambdaQuery = Wrappers.lambdaQuery();
        lambdaQuery.in(ExtIotNode::getNodeId,deviceCodes);
        return this.list(lambdaQuery);
    }

    public ExtIotNode getByNodeId(String deviceCode) {
        LambdaQueryWrapper<ExtIotNode> lambdaQuery = Wrappers.lambdaQuery();
        lambdaQuery.eq(ExtIotNode::getNodeId,deviceCode);
        return this.baseMapper.selectOne(lambdaQuery);
    }
}
